package meituan;

import java.util.Scanner;

/**
 * @Author Stringzhua
 * @Date 2024/11/9 15:24
 * description:
 */
public class test05 {
    public static boolean check(int mid, int a, int b, int c, int x, int y) {
        int diff = a - mid;
        b += diff / x;
        diff = b - mid;
        if (diff < 0) {
            return false;
        }
        c += diff / y;
        diff = c - mid;
        return diff >= 0;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for (int i = 0; i < t; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int x = sc.nextInt();
            int y = sc.nextInt();


            int lo = 0;
            int hi = a;

            while (lo < hi) {
                int mid = (lo + hi + 1) / 2;
                if (check(mid, a, b, c, x, y)) {
                    lo = mid;
                } else {
                    hi = mid - 1;
                }
            }
            System.out.println(lo);
        }
        sc.close();
    }
}
